home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / api.fr_ / api.fr (.txt)
Encoding:
Visual Basic Form  |  1995-07-19  |  9.3 KB  |  277 lines

  1. VERSION 4.00
  2. Begin VB.Form frmODBC 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "ODBC Database"
  5.    ClientHeight    =   5820
  6.    ClientLeft      =   1095
  7.    ClientTop       =   1470
  8.    ClientWidth     =   7365
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   0
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   6315
  19.    Left            =   990
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   5820
  22.    ScaleWidth      =   7365
  23.    Top             =   1080
  24.    Width           =   7575
  25.    Begin VB.ListBox lstODBCDrivers 
  26.       BackColor       =   &H00C0C0C0&
  27.       Height          =   1005
  28.       Left            =   240
  29.       Sorted          =   -1  'True
  30.       TabIndex        =   3
  31.       TabStop         =   0   'False
  32.       Top             =   2160
  33.       Width           =   4935
  34.    End
  35.    Begin VB.TextBox txtODBCStatus 
  36.       BackColor       =   &H00C0C0C0&
  37.       Height          =   315
  38.       Left            =   240
  39.       TabIndex        =   4
  40.       TabStop         =   0   'False
  41.       Top             =   4680
  42.       Width           =   6015
  43.    End
  44.    Begin VB.ListBox lstODBCDbs 
  45.       Height          =   1005
  46.       Left            =   240
  47.       TabIndex        =   1
  48.       Top             =   600
  49.       Width           =   4935
  50.    End
  51.    Begin VB.CommandButton cmdGetStatus 
  52.       Caption         =   "&Get ODBC Status"
  53.       Height          =   375
  54.       Left            =   240
  55.       TabIndex        =   5
  56.       Top             =   5280
  57.       Width           =   1695
  58.    End
  59.    Begin VB.CommandButton cmdQuit 
  60.       Caption         =   "&Quit"
  61.       Default         =   -1  'True
  62.       Height          =   375
  63.       Left            =   5040
  64.       TabIndex        =   6
  65.       Top             =   5280
  66.       Width           =   1215
  67.    End
  68.    Begin VB.Label lblDrivers 
  69.       BackColor       =   &H00C0C0C0&
  70.       Caption         =   "Installed ODBC Drivers:"
  71.       Height          =   255
  72.       Left            =   240
  73.       TabIndex        =   2
  74.       Top             =   1800
  75.       Width           =   3375
  76.    End
  77.    Begin VB.Label lblDatabases 
  78.       BackColor       =   &H00C0C0C0&
  79.       Caption         =   "&Registered ODBC Databases:"
  80.       Height          =   255
  81.       Left            =   240
  82.       TabIndex        =   0
  83.       Top             =   240
  84.       Width           =   3375
  85.    End
  86. Attribute VB_Name = "frmODBC"
  87. Attribute VB_Creatable = False
  88. Attribute VB_Exposed = False
  89. Option Explicit
  90. 'Dynamic arrays to hold data
  91. Dim dbName() As String
  92. Dim dbDesc() As String
  93. Dim DriverDesc() As String
  94. Dim DriverAttr() As String
  95. Private Sub cmdGetStatus_Click()
  96.     Dim result As Integer
  97.     'open the ODBC connection
  98.     result = ODBCAllocateEnv(ghEnv)
  99.     If result = SQL_SUCCESS Then
  100.         GetODBCdbs
  101.         GetODBCdvrs
  102.         cmdGetStatus.Enabled = False
  103.         txtODBCStatus.text = "Click one of the registered databases to obtain info."
  104.     Else
  105.         txtODBCStatus.text = "ODBC Information could not be retrieved."
  106.         Exit Sub
  107.     End If
  108. End Sub
  109. Private Sub cmdQuit_Click()
  110.     End
  111. End Sub
  112. Private Sub Form_Load()
  113.     txtODBCStatus.text = "Select Get ODBC Status to begin."
  114. End Sub
  115. Private Sub Form_Resize()
  116.     If Me.WindowState = NORMAL Then
  117.         If frmODBC.ScaleHeight < (9 * cmdQuit.Height) Then
  118.             frmODBC.Height = (11 * cmdQuit.Height)
  119.         End If
  120.         If frmODBC.ScaleWidth < (2 * (cmdQuit.Width + cmdGetStatus.Width)) Then
  121.             frmODBC.Width = (2 * (cmdQuit.Width + cmdGetStatus.Width))
  122.         End If
  123.         'Center the form
  124.         frmODBC.TOP = (Screen.Height - frmODBC.Height) / 2
  125.         frmODBC.Left = (Screen.Width - frmODBC.Width) / 2
  126.     End If
  127.     If Not (Me.WindowState = MINIMIZED) Then
  128.         RedrawForm
  129.     End If
  130. End Sub
  131. Private Sub Form_Unload(Cancel As Integer)
  132.     'Clean up the ODBC connections and allocations
  133.     Dim result As Integer
  134.     result = ODBCDisconnectDS(ghEnv, ghDbc, ghStmt)
  135.     result = ODBCFreeEnv(ghEnv)
  136. End Sub
  137. Private Sub GetODBCdbs()
  138.     Dim cbDSNMax As Integer
  139.     Dim szDSN As String * 33
  140.     #If Win32 Then
  141.         Dim pcbDSN As Long
  142.         Dim pcbDescription As Long
  143.     #Else
  144.         Dim pcbDSN As Integer
  145.         Dim pcbDescription As Integer
  146.     #End If
  147.     Dim szDescription As String * 512
  148.     Dim cbDescriptionMax As Integer
  149.     Dim result As Integer
  150.     Dim i As Integer
  151.     Dim nameLen As Integer
  152.     Dim ErrResult
  153.     cbDSNMax = SQL_MAX_DSN_LENGTH + 1
  154.     cbDescriptionMax = 512
  155.     result = SQL_SUCCESS
  156.     i = 0
  157.     Screen.MousePointer = HOURGLASS
  158.     Do While result <> SQL_NO_DATA_FOUND
  159.         'Get next data source (on the first call to
  160.         'SQLDataSources, SQL_FETCH_NEXT gets the first
  161.         'data source
  162.         result = SQLDataSources(ghEnv, SQL_FETCH_NEXT, szDSN, cbDSNMax, pcbDSN, szDescription, cbDescriptionMax, pcbDescription)
  163.         If result = SQL_ERROR Then
  164.             ErrResult = ODBCError("Env", ghEnv, 0, 0, result, "Error getting list of data sources.")
  165.             Screen.MousePointer = DEFAULT
  166.             Exit Sub
  167.         End If
  168.         
  169.         ReDim Preserve dbName(i)
  170.         dbName(i) = Left(szDSN, pcbDSN)
  171.         ReDim Preserve dbDesc(i)
  172.         dbDesc(i) = Left(szDescription, pcbDescription)
  173.         
  174.         lstODBCdbs.AddItem dbName(i) & "  (" & dbDesc(i) & ")"
  175.         
  176.         i = i + 1
  177.     Loop
  178.     Screen.MousePointer = DEFAULT
  179. End Sub
  180. Private Sub GetODBCdvrs()
  181.     Dim szDriverDesc As String * 512
  182.     Dim cbDriverDescMax As Integer
  183.     #If Win32 Then
  184.         Dim pcbDriverDesc As Long
  185.     #Else
  186.         Dim pcbDriverDesc As Integer
  187.     #End If
  188.     Dim szDriverAttributes As String * 2048
  189.     Dim cbDrvrAttrMax As Integer
  190.     #If Win32 Then
  191.         Dim pcbDrvrAttr As Long
  192.     #Else
  193.         Dim pcbDrvrAttr As Integer
  194.     #End If
  195.     Dim i As Integer
  196.     Dim result As Integer
  197.     Dim ErrResult As Integer
  198.     cbDriverDescMax = 512
  199.     cbDrvrAttrMax = 2048
  200.     result = SQL_SUCCESS
  201.     i = 0
  202.     Do While result <> SQL_NO_DATA_FOUND
  203.         result = SQLDrivers(ghEnv, SQL_FETCH_NEXT, szDriverDesc, cbDriverDescMax, pcbDriverDesc, szDriverAttributes, cbDrvrAttrMax, pcbDrvrAttr)
  204.         If result = SQL_ERROR Then
  205.             ErrResult = ODBCError("Env", ghEnv, 0, 0, result, "Error getting list of registered drivers.")
  206.             Exit Sub
  207.         End If
  208.         ReDim Preserve DriverDesc(i)
  209.         DriverDesc(i) = Left(szDriverDesc, pcbDriverDesc)
  210.         ReDim Preserve DriverAttr(i)
  211.         DriverAttr(i) = Left(szDriverAttributes, pcbDrvrAttr)
  212.         
  213.         lstODBCDrivers.AddItem DriverDesc(i) & "  (" & DriverAttr(i) & ")"
  214.         
  215.         i = i + 1
  216.     Loop
  217. End Sub
  218. Private Sub lstODBCDbs_Click()
  219.     Dim DataSource As String
  220.     Dim UserID As String
  221.     Dim Password As String
  222.     Dim result As Integer
  223.     Dim ErrResult As Integer
  224.     ReDim FuncList(100) As Integer
  225.     Dim i As Integer, j As Integer
  226.     Screen.MousePointer = HOURGLASS
  227.     DataSource = dbName(lstODBCdbs.ListIndex)
  228.     result = ODBCConnectDS(ghEnv, ghDbc, ghStmt, DataSource, UserID, Password)
  229.     If result <> SQL_SUCCESS Then
  230.         Screen.MousePointer = DEFAULT
  231.         Exit Sub
  232.     End If
  233.     'Now get the list of functions
  234.     result = SQLGetFunctions(ghDbc, SQL_API_ALL_FUNCTIONS, FuncList(0))
  235.     If result <> SQL_SUCCESS Then
  236.         ErrResult = ODBCError("Dbc", ghEnv, ghDbc, 0, result, "Error getting list of ODBC functions")
  237.         Screen.MousePointer = DEFAULT
  238.         Exit Sub
  239.     End If
  240.     Load frmAttributes
  241.     j = 0
  242.     For i = 0 To 99
  243.         If FuncList(i) <> 0 Then
  244.             frmAttributes.lstFunctions.AddItem ODBCFuncs(0, i)
  245.             j = j + 1
  246.         End If
  247.     Next
  248.     frmAttributes.txtFuncCount.text = j
  249.     frmAttributes.Caption = "Data Source: " & DataSource
  250.     frmAttributes.Show MODAL
  251.     'free the data source connection
  252.     result = ODBCDisconnectDS(ghEnv, ghDbc, SQL_NULL_HSTMT)
  253.     Screen.MousePointer = DEFAULT
  254. End Sub
  255. Private Sub RedrawForm()
  256.     Dim LBHeight As Integer
  257.     cmdQuit.TOP = frmODBC.ScaleHeight - (1.5 * cmdQuit.Height)
  258.     cmdQuit.Left = frmODBC.ScaleWidth - (1.25 * cmdQuit.Width)
  259.     cmdGetStatus.TOP = cmdQuit.TOP
  260.     cmdGetStatus.Left = 0.25 * cmdQuit.Width
  261.     txtODBCStatus.Left = cmdGetStatus.Left
  262.     txtODBCStatus.Width = frmODBC.ScaleWidth - (0.5 * cmdQuit.Width)
  263.     txtODBCStatus.TOP = cmdQuit.TOP - (1.5 * cmdQuit.Height)
  264.     'Area for each of two listbox:
  265.     LBHeight = (txtODBCStatus.TOP - lblDatabases.TOP) / 2.05
  266.     lstODBCdbs.TOP = lblDatabases.TOP + (1.25 * lblDatabases.Height)
  267.     lstODBCdbs.Left = cmdGetStatus.Left
  268.     lstODBCdbs.Width = frmODBC.ScaleWidth - (0.5 * cmdQuit.Width)
  269.     lstODBCdbs.Height = LBHeight - (1.5 * lblDatabases.Height)
  270.     lblDrivers.TOP = lblDatabases.TOP + LBHeight
  271.     lblDrivers.Height = lblDatabases.Height
  272.     lstODBCDrivers.TOP = lblDrivers.TOP + (1.25 * lblDrivers.Height)
  273.     lstODBCDrivers.Left = cmdGetStatus.Left
  274.     lstODBCDrivers.Width = frmODBC.ScaleWidth - (0.5 * cmdQuit.Width)
  275.     lstODBCDrivers.Height = LBHeight - (1.5 * lblDrivers.Height)
  276. End Sub
  277.